package common

import (
	"context"
	"git.mycaigou.com/gfyx/common/authorize"
	commonDto "git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/dto/common"
	"git.mycaigou.com/gfyx/micro-gfyx-api/infrastructure/repository/common"
	pb "git.mycaigou.com/gfyx/micro-gfyx-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/common"
	"git.myscrm.cn/golang/stark/v4"
)

type DmpReportService struct {
	commonRepo common.DmpReportRepositoryIface
}

func NewDmpReportService(commonRepo common.DmpReportRepositoryIface) DmpReportServiceIface {
	return &DmpReportService{
		commonRepo: commonRepo,
	}
}

func (d *DmpReportService) GetSsoLoginUrl(ctx context.Context, request *commonDto.DmpLoginUrlRequest) (*commonDto.DmpLoginUrlResponse, error) {
	// 获取租户 code
	tenantCode := ctx.Value(authorize.TENANT_CODE_KEY).(string)
	pbRequest := &pb.DmpLoginUrlRequest{
		TenantCode:   tenantCode,
		PageCode:     request.PageCode,
		ProvinceCode: request.ProvinceCode,
		Year:         request.Year,
		BusinessId:   request.BusinessId,
		StartDate:    request.StartDate,
		EndDate:      request.EndDate,
	}

	pbResp, err := d.commonRepo.GetSsoLoginUrl(ctx, pbRequest)
	if err != nil {
		stark.Logger.Error(ctx, "call dmp-login grpc failed:"+err.Error())
		return nil, err
	}

	return &commonDto.DmpLoginUrlResponse{Url: pbResp.GetUrl()}, nil
}
